﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SIAKADCORE.Controllers;
using SIAKADCORE.Models;
using SIAKADCORE.Helpers;
using System.Data;
using System.IO;

namespace SIAKADTEST
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //TestTambahPenggunaMahasiswa();
            //TestTambahPenggunaDosen();
            //TestTambahPenggunaPegawai();
            //TestMatakuliah();
            //PertemuanContoh();

            //CobaHariIni();

            //TampilinKuisioner();

            //var usr = new User()
            //{
            //    IdUser = UserController.GetID(),
            //    Username = "admin",
            //    Password = new AesCipherUtility("reintasa", "cantik").Encrypt("wulanimut"),
            //    IdRole = "RL008"
            //};

            //UserController.Tambah(usr);

            Console.ReadKey();
        }

        private static void TampilinKuisioner()
        {
            var dataset = new DataSet();
            bool ambilKuisioner =  KuisionerController.GetTabelPreview("DPM0000001", out dataset);

            int i = 0;

            foreach (DataRow item in dataset.Tables[0].Rows)
            {
                Console.Write(++i);
                Console.WriteLine(". {0}", item[3].ToString());
                
                char c = 'a';
                Console.Write(c++);
                Console.WriteLine(". {0}", item[4].ToString());
                Console.Write(c++);
                Console.WriteLine(". {0}", item[5].ToString());
                Console.Write(c++);
                Console.WriteLine(". {0}", item[6].ToString());
                Console.Write(c++);
                Console.WriteLine(". {0}", item[7].ToString());
            }
        }

        //private static void CobaHariIni()
        //{
        //    // Detail Pertanyaan
        //    var detailPertanyaan = new DetailPengambilanMatakuliah
        //    {
        //        IdDetailMatakuliah = DetailPengambilanMatakuliahController.GetID(),
        //        IdDetailPengambilanMatakuliah = "",
        //        IdMahasiswa = ""
        //    };
        //}

        private static void PertemuanContoh()
        {
            Pertemuan p = new Pertemuan
            {
                IdPertemuan = PertemuanController.GetID(),
                JumlahPertemuan = 18
            };

            PertemuanController.Tambah(p);
        }

        public static void TestTambahPenggunaMahasiswa()
        {
            string[] mahasiswas = File.ReadAllLines(@"Data\Mahasiswa.txt");
            mahasiswas.ToList().ForEach(mahasiswa =>
            {
                string[] temp = mahasiswa.Split(new char[] { ';' });
                
                var mhs = new Mahasiswa()
                {
                    IdMahasiswa = MahasiswaController.GetID(),
                    NamaMahasiswa = temp[0],
                    Nrp = temp[1]
                };

                var usr = new User()
                {
                    IdUser = UserController.GetID(),
                    Username = mhs.Nrp,
                    Password = new AesCipherUtility("reintasa", "cantik").Encrypt(mhs.Nrp),
                    IdRole = "RL006",
                    IdMahasiswa = mhs.IdMahasiswa
                };

                UserController.Tambah(usr, mhs);
            });
        }

        public static void TestTambahPenggunaDosen()
        {
            string[] dosens = File.ReadAllLines(@"Data\Dosen.txt");
            dosens.ToList().ForEach(dosen =>
            {
                string[] temp = dosen.Split(new char[] { ';' });

                var dsn = new Dosen()
                {
                    IdDosen = DosenController.GetID(),
                    NamaDosen = temp[0],
                    Nip = temp[1]
                };

                var usr = new User()
                {
                    IdUser = UserController.GetID(),
                    Username = dsn.Nip,
                    Password = new AesCipherUtility("reintasa", "cantik").Encrypt(dsn.Nip),
                    IdRole = "RL002",
                    IdDosen = dsn.IdDosen
                };

                UserController.Tambah(usr, dsn);
            });
        }

        public static void TestTambahPenggunaPegawai()
        {
            string[] pegawais = File.ReadAllLines(@"Data\Pegawai.txt");
            pegawais.ToList().ForEach(pegawai =>
            {
                string[] temp = pegawai.Split(new char[] { ';' });

                var pgw = new Pegawai()
                {
                    IdPegawai = PegawaiController.GetID(),
                    NamaPegawai = temp[0],
                    Nip = temp[1]
                };

                var usr = new User()
                {
                    IdUser=UserController.GetID(),
                    Username = pgw.Nip,
                    Password = new AesCipherUtility("reintasa", "cantik").Encrypt(pgw.Nip),
                    IdRole="RL007",
                    IdPegawai = pgw.IdPegawai
                };

                UserController.Tambah(usr, pgw);
            });
        }

        public static void TestMatakuliah()
        {
            string[] matakuliahs = File.ReadAllLines(@"Data\Matakuliah.txt");
            matakuliahs.ToList().ForEach(matakuliah =>
            {
                var mk = new Matakuliah()
                {
                    IdMatakuliah = MatakuliahController.GetID(),
                    NamaMatakuliah = matakuliah
                };

                MatakuliahController.Tambah(mk);
            });
        }
    }
}
